package com.custom.readerviewpager.Activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import com.custom.readerviewpager.R;
import com.custom.readerviewpager.View.CustomReaderViewPager;
import com.custom.readerviewpager.View.CustomReaderViewPager2;
import com.custom.readerviewpager.View.CustomReaderViewPager3;
import com.custom.readerviewpager.adapter.MyPageAdapter;
import com.custom.readerviewpager.adapter.MyPageAdapter2;
import com.custom.readerviewpager.adapter.MyPageAdapter3;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    public List<View> mViews;
    public List<View> mViews2;
    public List<View> mViews3;
    private CustomReaderViewPager mViewPage;
    private CustomReaderViewPager2 mViewPage2;
    private CustomReaderViewPager3 mViewPage3;
    private MyPageAdapter mMyPageAdapter;
    private MyPageAdapter2 mMyPageAdapter2;
    private MyPageAdapter3 mMyPageAdapter3;
    public View mView1;
    public View mView2;
    public View mView3;
    public View mView4;
    public View mView5;
    public View mView6;
    public View mView7;
    public View mView8;
    public View mView9;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//版本判断
            // Translucent status bar
            this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//设置statusbar应用所占的屏幕扩大到全屏，但是最顶上会有背景透明的状态栏，它的文字可能会盖着你的应用的标题栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();

        mViewPage2.setCurrentItem(1);    //设置当前显示哪个子元素
        mViewPage2.setPageMargin(10);//设置左右相距
        mViewPage2.setOffscreenPageLimit(3);//设置预加载的页数 默认为1

        mViewPage3.setPageMargin(40);//设置左右相距
        mViewPage3.setCurrentItem(1);    //设置当前显示哪个子元素
    }


    /**
     * 初始化
     */
    private void init() {
        mViewPage = findViewById(R.id.vp_main_homepage);
        mViewPage2 = findViewById(R.id.vp_main_homepage2);
        mViewPage3 = findViewById(R.id.vp_main_homepage3);
        mView1 = LayoutInflater.from(MainActivity.this).inflate(R.layout.view1, null);
        mView2 = LayoutInflater.from(MainActivity.this).inflate(R.layout.view2, null);
        mView3 = LayoutInflater.from(MainActivity.this).inflate(R.layout.view3, null);
        mView4 = LayoutInflater.from(MainActivity.this).inflate(R.layout.view4, null);
        mView5 = LayoutInflater.from(MainActivity.this).inflate(R.layout.view5, null);
        mView6 = LayoutInflater.from(MainActivity.this).inflate(R.layout.view6, null);
        mView7 = LayoutInflater.from(MainActivity.this).inflate(R.layout.view7, null);
        mView8 = LayoutInflater.from(MainActivity.this).inflate(R.layout.view8, null);
        mView9= LayoutInflater.from(MainActivity.this).inflate(R.layout.view9, null);
        mViews = new ArrayList<>();
        mViews2 = new ArrayList<>();
        mViews3=new ArrayList<>();
        mViews.add(mView1);
        mViews.add(mView2);
        mViews.add(mView3);

        mViews2.add(mView4);
        mViews2.add(mView5);
        mViews2.add(mView6);


        mViews3.add(mView7);
        mViews3.add(mView8);
        mViews3.add(mView9);
        mMyPageAdapter = new MyPageAdapter(mViews, MainActivity.this);
        mViewPage.setAdapter(mMyPageAdapter);

        mMyPageAdapter2 = new MyPageAdapter2(mViews2, MainActivity.this);
        mViewPage2.setAdapter(mMyPageAdapter2);


        mMyPageAdapter3 = new MyPageAdapter3(mViews3, MainActivity.this);
        mViewPage3.setAdapter(mMyPageAdapter3);
    }
}
